/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GUISeletorContatos.java
 *
 * Created on 05/12/2010, 00:39:36
 */
package ifpb.pod.cliente.visao;

import ifpb.pod.model.ContaUsuario;
import ifpb.pod.model.Contato;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import javax.swing.DefaultListModel;

/**
 *
 * @author Diogenes
 */
public class GUISeletorContatos extends javax.swing.JFrame {

    private DefaultListModel modelContatos;
    private DefaultListModel modelContatosNoticia;

    /** Creates new form GUISeletorContatos */
    public GUISeletorContatos(DefaultListModel modelContatos, DefaultListModel modelContatosNoticia) {
        initComponents();
        this.modelContatos = modelContatos;
        this.modelContatosNoticia = modelContatosNoticia;
        iniciaLista();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane2 = new javax.swing.JScrollPane();
        lContatos = new javax.swing.JList();
        jScrollPane1 = new javax.swing.JScrollPane();
        lContatosNoticia = new javax.swing.JList();
        bAdd = new javax.swing.JButton();
        bRem = new javax.swing.JButton();
        bConfirmar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        lContatos.setBorder(javax.swing.BorderFactory.createTitledBorder("Contatos"));
        lContatos.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        lContatos.setOpaque(false);
        lContatos.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                lContatosFocusGained(evt);
            }
        });
        jScrollPane2.setViewportView(lContatos);

        getContentPane().add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 11, 229, 327));

        lContatosNoticia.setBorder(javax.swing.BorderFactory.createTitledBorder("Contatos da Notícia"));
        lContatosNoticia.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        lContatosNoticia.setOpaque(false);
        lContatosNoticia.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                lContatosNoticiaFocusGained(evt);
            }
        });
        jScrollPane1.setViewportView(lContatosNoticia);

        getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 10, 229, 327));

        bAdd.setText(">>");
        bAdd.setEnabled(false);
        bAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bAddActionPerformed(evt);
            }
        });
        getContentPane().add(bAdd, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 10, -1, -1));

        bRem.setText("<<");
        bRem.setEnabled(false);
        bRem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bRemActionPerformed(evt);
            }
        });
        getContentPane().add(bRem, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 40, -1, -1));

        bConfirmar.setText("Confirmar");
        bConfirmar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bConfirmarActionPerformed(evt);
            }
        });
        getContentPane().add(bConfirmar, new org.netbeans.lib.awtextra.AbsoluteConstraints(460, 340, -1, -1));

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-564)/2, (screenSize.height-410)/2, 564, 410);
    }// </editor-fold>//GEN-END:initComponents

    private void bAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bAddActionPerformed
        try {
            this.modelContatosNoticia.addElement(this.modelContatos.remove(lContatos.getSelectedIndex()));
        } catch (Exception ex) {
            System.out.println("não tem para selecionar");
        }

    }//GEN-LAST:event_bAddActionPerformed

    private void bRemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bRemActionPerformed
        try {
            modelContatos.addElement(modelContatosNoticia.remove(lContatosNoticia.getSelectedIndex()));
        } catch (Exception ex) {
            System.out.println("não tem para selecionar");
        }

    }//GEN-LAST:event_bRemActionPerformed

    private void bConfirmarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bConfirmarActionPerformed
//        List<Contato> contatos = new ArrayList<Contato>();
//        for (Object contato : Arrays.asList(modelContatosNoticia.toArray())) {
//            contatos.add((Contato)contato);
//        }
        this.dispose();


    }//GEN-LAST:event_bConfirmarActionPerformed

    private void lContatosFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_lContatosFocusGained
        bAdd.setEnabled(true);
        bRem.setEnabled(false);
    }//GEN-LAST:event_lContatosFocusGained

    private void lContatosNoticiaFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_lContatosNoticiaFocusGained
        bAdd.setEnabled(false);
        bRem.setEnabled(true);
    }//GEN-LAST:event_lContatosNoticiaFocusGained
    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bAdd;
    private javax.swing.JButton bConfirmar;
    private javax.swing.JButton bRem;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JList lContatos;
    private javax.swing.JList lContatosNoticia;
    // End of variables declaration//GEN-END:variables

    private void iniciaLista() {
//        this.modelContatos = new DefaultListModel();
        this.lContatos.setModel(modelContatos);

//        this.modelContatosNoticia = new DefaultListModel();
        this.lContatosNoticia.setModel(modelContatosNoticia);

    }
}
